
{% block sw_settings_shipping_detail %}
<sw-page class="sw-settings-shipping-detail">

    {% block sw_settings_shipping_detail_header %}
    <template #smart-bar-header>
        <h2>{{ placeholder(shippingMethod, 'name', $tc('sw-settings-shipping.detail.textHeadline')) }}</h2>
    </template>
    {% endblock %}

    {% block sw_settings_shipping_detail_actions %}
    <template #smart-bar-actions>
        {% block sw_settings_shipping_detail_actions_abort %}
        <mt-button
            v-tooltip.bottom="tooltipCancel"
            :disabled="isLoading || undefined"
            variant="secondary"
            size="default"
            @click="onCancel"
        >
            {{ $tc('global.default.cancel') }}
        </mt-button>
        {% endblock %}

        {% block sw_settings_shipping_detail_actions_save %}
        <sw-button-process
            v-model:process-success="isSaveSuccessful"
            v-tooltip.bottom="tooltipSave"
            class="sw-settings-shipping-method-detail__save-action"
            :is-loading="isProcessLoading"
            :disabled="isProcessLoading || !acl.can('shipping.editor') || undefined"
            variant="primary"
            @click.prevent="onSave"
        >
            {{ $tc('sw-settings-shipping.detail.buttonSave') }}
        </sw-button-process>
        {% endblock %}
    </template>
    {% endblock %}

    {% block sw_settings_shipping_detail_language_switch %}
    <template #language-switch>
        <sw-language-switch
            :disabled="isNewShippingMethod || undefined"
            :save-changes-function="saveOnLanguageChange"
            :abort-change-function="abortOnLanguageChange"
            @on-change="onChangeLanguage"
        />
    </template>
    {% endblock %}

    {% block sw_settings_shipping_detail_content %}
    <template #content>
        <sw-card-view>
            <template v-if="isLoading">
                <sw-skeleton variant="detail-bold" />
                <sw-skeleton />
            </template>

            <template v-else>
                {% block sw_settings_shipping_detail_content_language_info %}
                <sw-language-info
                    :is-new-entity="isNewShippingMethod"
                    :entity-description="placeholder(shippingMethod, 'name', $tc('sw-settings-shipping.detail.textHeadline'))"
                />
                {% endblock %}

                {% block sw_settings_shipping_detail_base %}
                <mt-card
                    position-identifier="sw-settings-shipping-detail-base"
                    :title="$tc('sw-settings-shipping.detail.labelBasicInfo')"
                    :is-loading="isLoading"
                >
                    <sw-container
                        columns="3fr 3fr"
                        gap="0px 30px"
                    >
                        {% block sw_settings_shipping_detail_base_content_field_name %}

                        <mt-text-field
                            v-model="shippingMethod.name"
                            name="sw-field--shippingMethod-name"
                            required
                            :disabled="!acl.can('shipping.editor') || undefined"
                            :error="shippingMethodNameError"
                            :label="$tc('sw-settings-shipping.detail.labelName')"
                            :placeholder="placeholder(shippingMethod, 'name', $tc('sw-settings-shipping.detail.placeholderName'))"
                        />
                        {% endblock %}

                        {% block sw_settings_shipping_detail_content_field_technical_name %}

                        <mt-text-field
                            v-model="shippingMethod.technicalName"
                            name="sw-field--shippingMethod-technicalName"
                            class="sw-settings-shipping-detail__field-technical-name"
                            required
                            :disabled="!acl.can('shipping.editor') || undefined"
                            :label="$tc('sw-settings-shipping.detail.labelTechnicalName')"
                            :placeholder="placeholder(shippingMethod, 'technicalName', $tc('sw-settings-shipping.detail.placeholderTechnicalName'))"
                            :error="shippingMethodTechnicalNameError"
                            :help-text="$tc('sw-settings-shipping.detail.helpTextTechnicalName')"
                        />
                        {% endblock %}

                        {% block sw_settings_shipping_detail_base_content_field_position %}
                        <mt-number-field
                            v-model="shippingMethod.position"
                            name="sw-field--shippingMethod-position"
                            class="sw-settings-shipping-detail__field-position"
                            :step="1"
                            :disabled="!acl.can('shipping.editor') || undefined"
                            :label="$tc('sw-settings-shipping.detail.labelPosition')"
                            :placeholder="$tc('sw-settings-shipping.detail.placeholderPosition')"
                        />
                        {% endblock %}
                        {% block sw_settings_shipping_detail_base_content_field_active %}

                        <mt-switch
                            v-model="shippingMethod.active"
                            name="sw-field--shippingMethod-active"
                            bordered
                            :disabled="!acl.can('shipping.editor') || undefined"
                            :label="$tc('sw-settings-shipping.detail.labelActive')"
                        />
                        {% endblock %}
                    </sw-container>
                    <sw-container
                        columns="repeat(auto-fit, minmax(250px, 1fr))"
                        gap="0px 30px"
                    >
                        {% block sw_settings_shipping_detail_base_content_field_description %}
                        <mt-textarea
                            v-model="shippingMethod.description"
                            name="sw-field--shippingMethod-description"
                            :model-value="shippingMethod.description"
                            class="sw-settings-shipping-detail__description"
                            :disabled="!acl.can('shipping.editor') || undefined"
                            :label="$tc('sw-settings-shipping.detail.labelDescription')"
                            :placeholder="placeholder(shippingMethod, 'description', $tc('sw-settings-shipping.detail.placeholderDescription'))"
                        />
                        {% endblock %}

                        {% block sw_settings_shipping_detail_base_content_media_upload %}
                        <sw-upload-listener
                            :upload-tag="uploadTag"
                            auto-upload
                            @media-upload-finish="setMediaItem"
                        />
                        <sw-media-upload-v2
                            v-if="!isLoading"
                            :upload-tag="uploadTag"
                            :source="logoMediaItem"
                            class="sw-settings-shipping-detail__logo-image-upload"
                            :allow-multi-select="false"
                            variant="regular"
                            :disabled="!acl.can('shipping.editor') || undefined"
                            :label="$tc('sw-settings-shipping.detail.labelLogoUpload')"
                            :default-folder="shippingMethod.getEntityName()"
                            @media-drop="onDropMedia"
                            @media-upload-sidebar-open="openMediaSidebar"
                            @media-upload-remove-image="onUnlinkLogo"
                        />
                        {% endblock %}
                    </sw-container>

                    {% block sw_settings_shipping_detail_base_content_field_delivery_time %}
                    <sw-entity-single-select
                        v-model:value="shippingMethod.deliveryTimeId"
                        name="sw-field--shippingMethod-deliveryTimeId"
                        class="sw-settings-shipping-detail__delivery-time"
                        entity="delivery_time"
                        :disabled="!acl.can('shipping.editor') || undefined"
                        :criteria="deliveryTimeCriteria"
                        :label="$tc('sw-settings-shipping.detail.labelDeliveryTime')"
                        :placeholder="$tc('sw-settings-shipping.detail.placeholderDeliveryTime')"
                        :error="shippingMethodDeliveryTimeIdError"
                        show-clearable-button
                        required
                    />
                    {% endblock %}

                    {% block sw_settings_shipping_detail_base_content_tracking_url_field %}

                    <mt-text-field
                        v-model="shippingMethod.trackingUrl"
                        name="sw-field--shippingMethod-trackingUrl"
                        :disabled="!acl.can('shipping.editor') || undefined"
                        :label="$tc('sw-settings-shipping.detail.labelTrackingUrl')"
                        :placeholder="placeholder(shippingMethod, 'trackingUrl', $tc('sw-settings-shipping.detail.placeholderTrackingUrl'))"
                        :help-text="$tc('sw-settings-shipping.detail.helpTextTrackingUrl')"
                    />
                    {% endblock %}

                    {% block sw_settings_shipping_detail_base_content_tags_field %}
                    <sw-entity-tag-select
                        v-if="!isLoading"
                        v-model:entity-collection="shippingMethod.tags"
                        :disabled="!acl.can('shipping.editor') || undefined"
                        :placeholder="$tc('sw-product.categoryForm.placeholderTags')"
                    />
                    {% endblock %}
                </mt-card>
                {% endblock %}

                {% block sw_settings_shipping_detail_top_ruleshippingPriceStore %}
                <mt-card
                    position-identifier="sw-settings-shipping-detail-condition-container"
                    class="sw-settings-shipping-detail__condition_container"
                    :title="$tc('sw-settings-shipping.detail.topRule')"
                >
                    {% block sw_settings_shipping_detail_top_rule_select %}
                    <sw-select-rule-create
                        :rule-id="shippingMethod.availabilityRuleId"
                        :rule-filter="ruleFilter"
                        :disabled="!acl.can('shipping.editor') || undefined"
                        :error="shippingMethodAvailabilityRuleIdError"
                        :label="$tc('sw-settings-shipping.detail.topRule')"
                        :placeholder="$tc('sw-settings-shipping.detail.placeholderTopRule')"
                        class="sw-settings-shipping-detail__top-rule"
                        rule-aware-group-key="shippingMethods"
                        @save-rule="onSaveRule"
                    />
                    {% endblock %}
                </mt-card>
                {% endblock %}

                {% block sw_settings_shipping_detail_tax_cost %}
                <sw-settings-shipping-tax-cost
                    v-if="!isLoading"
                    :disabled="!acl.can('shipping.editor') || undefined"
                />
                {% endblock %}
                <sw-skeleton v-else />

                {% block sw_settings_shipping_detail_price_matrices %}
                <sw-settings-shipping-price-matrices
                    v-if="!isLoading"
                    ref="priceMatrices"
                    :disabled="!acl.can('shipping.editor') || undefined"
                />
                {% endblock %}
                <sw-skeleton v-else />

                {% block sw_settings_shipping_detail_custom_field_sets %}
                <mt-card
                    v-if="showCustomFields"
                    position-identifier="sw-settings-shipping-detail-custom-fields"
                    :title="$tc('sw-settings-custom-field.general.mainMenuItemGeneral')"
                    :is-loading="isLoading"
                >
                    <sw-custom-field-set-renderer
                        :entity="shippingMethod"
                        :disabled="!acl.can('shipping.editor') || undefined"
                        :sets="customFieldSets"
                    />
                </mt-card>
                {% endblock %}
            </template>
        </sw-card-view>
    </template>
    {% endblock %}

    <template #sidebar>
        {% block sw_settings_shipping_detail_sidebar %}
        <sw-sidebar :propagate-width="true">
            {% block sw_setting_shipping_detail_sidebar_media_item %}
            <sw-sidebar-media-item ref="mediaSidebarItem">
                <template
                    #context-menu-items="media"
                >
                    <sw-context-menu-item @click="setMediaFromSidebar(media.mediaItem)">
                        {{ $tc('sw-settings-shipping.sidebar.labelUseAsLogo') }}
                    </sw-context-menu-item>
                </template>
            </sw-sidebar-media-item>
            {% endblock %}
        </sw-sidebar>
        {% endblock %}
    </template>

</sw-page>
{% endblock %}
